package gunfire.relics;

import basemod.abstracts.CustomRelic;
import com.badlogic.gdx.graphics.Texture;
import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.actions.common.ApplyPowerToRandomEnemyAction;
import com.megacrit.cardcrawl.actions.common.RelicAboveCreatureAction;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import com.megacrit.cardcrawl.relics.AbstractRelic;
import gunfire.GunfireMod;
import gunfire.actions.ElementalEffectAction;
import gunfire.powers.BurningPower;
import gunfire.powers.DecayPower;
import gunfire.powers.ShockPower;
import gunfire.util.TextureLoader;

import static gunfire.GunfireMod.makeRelicOutlinePath;
import static gunfire.GunfireMod.makeRelicPath;

public class ElementalTorment extends CustomRelic {

    public static final String ID = GunfireMod.makeID("ElementalTorment");
    private static final Texture IMG = TextureLoader.getTexture(makeRelicPath("ElementalTorment.png"));
    private static final Texture OUTLINE = TextureLoader.getTexture(makeRelicOutlinePath("blank.png"));

    public ElementalTorment() {
        super(ID, IMG, OUTLINE, RelicTier.RARE, LandingSound.CLINK);
    }

    @Override
    public void onMonsterDeath(AbstractMonster m) {
        if (m.hasPower("gunfire:BurningPower") || m.hasPower("gunfire:DecayPower") || m.hasPower("gunfire:ShockPower")) {
            int amount = 0, type = -1;
            if(m.hasPower("gunfire:BurningPower")){
                amount = m.getPower("gunfire:BurningPower").amount;
                type = 0;
            } else if(m.hasPower("gunfire:DecayPower")){
                amount = m.getPower("gunfire:DecayPower").amount;
                type = 1;
            } else if(m.hasPower("gunfire:ShockPower")){
                amount = m.getPower("gunfire:ShockPower").amount;
                type = 2;
            }
            if (!AbstractDungeon.getMonsters().areMonstersBasicallyDead()) {
                this.flash();
                this.addToBot(new RelicAboveCreatureAction(m, this));
                AbstractMonster mo = AbstractDungeon.getRandomMonster();
                if(type == 0){
                    this.addToBot(new ElementalEffectAction(mo, AbstractDungeon.player, amount, GunfireMod.ElementalEffect.Burning));
                } else if(type == 1){
                    this.addToBot(new ElementalEffectAction(mo, AbstractDungeon.player, amount, GunfireMod.ElementalEffect.Decay));
                } else if(type == 2){
                    this.addToBot(new ElementalEffectAction(mo, AbstractDungeon.player, amount, GunfireMod.ElementalEffect.Shock));
                }
            }
        }
    }

    @Override
    public String getUpdatedDescription() {
        return DESCRIPTIONS[0];
    }

    @Override
    public AbstractRelic makeCopy() {
        return new ElementalTorment();
    }
}
